package com.meelive.ingkee.iknetwork.diagnose.util

import android.text.TextUtils
import android.util.Log
import com.google.gson.Gson

object DiagnosePares {

    private val gson : Gson by lazy {
        Gson()
    }

    fun toJson(obj: Any?): String? {
        return try {
            gson.toJson(obj)
        } catch (e: Exception) {
            ""
        }
    }

    fun <E> parseJson(json: String?, clazz: Class<E>): E? {
        return if (TextUtils.isEmpty(json)) {
            null
        } else try {
            gson.fromJson(json, clazz)
        } catch (e: Exception) {
            Log.e("IKLog",
                    "解析json过程中发生异常: json: + " + json + " class: " + clazz.name, e)
            null
        }
    }
}